<?php

  /**
   * Autors
   *
   * Класс виджета, выводящего авторов
   */

  class Autors extends XMLWidget
  {
    /**
     * запустить виджет
     *
     * @return void
     * @access public
     */
    public function run()
    {
      $groups = array();
      /** @var $autor User */
      foreach (User::model()->autors()->findAll() as $autor)
      {
        $category = $autor->category->name;
        array_key_exists($category, $groups) or ($groups[$category] = array());
        $groups[$category][] = $autor;
      }

      if (!empty($groups))
      {
        self::openNode("autors");

        foreach ($groups as $category => &$autors)
        {
          self::openNode("category", array("name" => $category));
            array_walk($autors, create_function('User $u', 'XMLWidget::autorNode($u);'));
          self::closeNode("category");
        }

        self::closeNode("autors");
      }
    }
  }

?>